package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Hotel;
import cn.wolfcode.trip.base.mapper.HotelMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IHotelService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HotelServiceImpl implements IHotelService {
    @Autowired
    private HotelMapper hotelMapper;

    @Override
    public void saveOrUpdate(Hotel entity) {
        if (entity.getId() == null) {
            hotelMapper.insert(entity);
        } else {
            hotelMapper.updateByPrimaryKey(entity);
        }
    }

    @Override
    public PageInfo<Hotel> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<Hotel> list = hotelMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public List<Hotel> selectHotelByRegions(Long cityId) {
        return hotelMapper.selectForCity(cityId);
    }

    @Override
    public Hotel get(Long hotelId) {
        return hotelMapper.selectByPrimaryKey(hotelId);
    }

}
